<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'>
  <head>
    <title>app/models/user.rb</title>
    <link href="screen.css" media="all" rel="stylesheet" type="text/css" />
    <link href="print.css" media="print" rel="stylesheet" type="text/css" />
    
    <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
    <script type="text/javascript" src="rcov.js"></script>
  </head>
  <body>
    <h1>Survey0 3 C0 Coverage Information - RCov</h1>
    <h2>app/models/user.rb</h2>

    

    <div class="report_table_wrapper">
      <table class='report' id='report_table'>
        <thead>
          <tr>
            <th class="left_align">Name</th>
            <th class="right_align">Total Lines</th>
            <th class="right_align">Lines of Code</th>
            <th class="left_align">Total Coverage</th>
            <th class="left_align">Code Coverage</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td class="left_align"><a href="app-models-user_rb.html">app/models/user.rb</a></td>
            <td class='right_align'><tt>136</tt></td>
            <td class='right_align'><tt>108</tt></td>
            <td class="left_align"><div class="percent_graph_legend"><tt class=''>50.74%</tt></div>
          <div class="percent_graph">
            <div class="covered" style="width:51px"></div>
            <div class="uncovered" style="width:49px"></div>
          </div></td>
            <td class="left_align"><div class="percent_graph_legend"><tt class=''>41.67%</tt></div>
          <div class="percent_graph">
            <div class="covered" style="width:42px"></div>
            <div class="uncovered" style="width:58px"></div>
          </div></td>
          </tr>
        </tbody>
      </table>
    </div>
    
    <h3>Key</h3>
    
    <div class="key"><pre><span class='marked'>Code reported as executed by Ruby looks like this...</span><span class='marked1'>and this: this line is also marked as covered.</span><span class='inferred'>Lines considered as run by rcov, but not reported by Ruby, look like this,</span><span class='inferred1'>and this: these lines were inferred by rcov (using simple heuristics).</span><span class='uncovered'>Finally, here's a line marked as not executed.</span></pre></div>

    <h3>Coverage Details</h3>

    <table class="details">
      <tbody>
        
          
          
          <tr class="marked">
            <td><pre><a name="line1">1</a> require 'digest'</pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line2">2</a> </pre></td>
          </tr>
        
          
          
          <tr class="marked">
            <td><pre><a name="line3">3</a> class User &lt; ActiveRecord::Base</pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line4">4</a> </pre></td>
          </tr>
        
          
          
          <tr class="marked">
            <td><pre><a name="line5">5</a>   has_many :original_results</pre></td>
          </tr>
        
          
          
          <tr class="marked">
            <td><pre><a name="line6">6</a>   has_many :pre_original_results</pre></td>
          </tr>
        
          
          
          <tr class="marked">
            <td><pre><a name="line7">7</a>   has_and_belongs_to_many :stests, :join_table =&gt; &quot;users_surveys&quot;, :class_name =&gt; &quot;Survey&quot;</pre></td>
          </tr>
        
          
          
          <tr class="marked">
            <td><pre><a name="line8">8</a>   has_many :test_records</pre></td>
          </tr>
        
          
          
          <tr class="marked">
            <td><pre><a name="line9">9</a>   has_many :surveys</pre></td>
          </tr>
        
          
          
          <tr class="marked">
            <td><pre><a name="line10">10</a>   has_many :temp_users ,:foreign_key =&gt; &quot;org_id&quot;</pre></td>
          </tr>
        
          
          
          <tr class="marked">
            <td><pre><a name="line11">11</a>   has_many :pre_test_records</pre></td>
          </tr>
        
          
          
          <tr class="marked">
            <td><pre><a name="line12">12</a>   has_and_belongs_to_many :tests, :join_table =&gt; &quot;orgs_surveys&quot;, :foreign_key =&gt; &quot;org_id&quot; ,:class_name =&gt; &quot;Survey&quot;</pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line13">13</a> </pre></td>
          </tr>
        
          
          
          <tr class="marked">
            <td><pre><a name="line14">14</a>   validates_presence_of :username</pre></td>
          </tr>
        
          
          
          <tr class="marked">
            <td><pre><a name="line15">15</a>   validates_uniqueness_of :username</pre></td>
          </tr>
        
          
          
          <tr class="marked">
            <td><pre><a name="line16">16</a>   validates_length_of :password, :in =&gt; 6..20, :on =&gt; :create</pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line17">17</a> </pre></td>
          </tr>
        
          
          
          <tr class="marked">
            <td><pre><a name="line18">18</a>   attr_accessor :password_confirmation</pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line19">19</a>   #validates_confirmation_of :password</pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line20">20</a>   </pre></td>
          </tr>
        
          
          
          <tr class="marked">
            <td><pre><a name="line21">21</a>   def password</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line22">22</a>     @password</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line23">23</a>   end</pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line24">24</a>   </pre></td>
          </tr>
        
          
          
          <tr class="marked">
            <td><pre><a name="line25">25</a>   def password=(pwd)</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line26">26</a>     @password=pwd</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line27">27</a>     return if pwd.blank?</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line28">28</a>     create_new_salt</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line29">29</a>     self.passwordconf=User.encrypted_passwed(self.password, self.salt)</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line30">30</a>   end </pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line31">31</a>   </pre></td>
          </tr>
        
          
          
          <tr class="marked">
            <td><pre><a name="line32">32</a>   def self.authenticate(name, passwd)</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line33">33</a>     user = self.find_by_username(name)</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line34">34</a>     if user</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line35">35</a>      e_passwd=encrypted_passwed(passwd, user.salt)</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line36">36</a>       if user.passwordconf != e_passwd</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line37">37</a>         user =nil </pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line38">38</a>       end</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line39">39</a>     end </pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line40">40</a>     user</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line41">41</a>   end</pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line42">42</a> </pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line43">43</a>     </pre></td>
          </tr>
        
          
          
          <tr class="marked">
            <td><pre><a name="line44">44</a>   def self.search(search, page)  </pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line45">45</a>     paginate :per_page =&gt; 10, :page =&gt; page,  </pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line46">46</a>     :conditions =&gt; ['username like ?', &quot;%#{search}%&quot;],  </pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line47">47</a>     :order =&gt; 'id'  </pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line48">48</a>   end</pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line49">49</a> </pre></td>
          </tr>
        
          
          
          <tr class="marked">
            <td><pre><a name="line50">50</a>   def self.info_completed?(id)</pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line51">51</a>     user = self.find_by_id(id)</pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line52">52</a>     return user.is_complete == USER_INFO_COMPLETED ? true : false</pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line53">53</a>   end</pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line54">54</a> </pre></td>
          </tr>
        
          
          
          <tr class="marked">
            <td><pre><a name="line55">55</a>   def tested?(test)</pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line56">56</a>     logger.info &quot;Processing in user.tested&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&quot;</pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line57">57</a>     self.stests.include?(test)</pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line58">58</a>   end</pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line59">59</a> </pre></td>
          </tr>
        
          
          
          <tr class="marked">
            <td><pre><a name="line60">60</a>   def just_test(test)</pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line61">61</a>     unless tests.include? test</pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line62">62</a>       stests &lt;&lt; test</pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line63">63</a>     end</pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line64">64</a>   end</pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line65">65</a> </pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line66">66</a> </pre></td>
          </tr>
        
          
          
          <tr class="marked">
            <td><pre><a name="line67">67</a>   def create_new_salt</pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line68">68</a>     self.salt=self.object_id.to_s+rand.to_s</pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line69">69</a>   end</pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line70">70</a> </pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line71">71</a>   #批量添加试用机构</pre></td>
          </tr>
        
          
          
          <tr class="marked">
            <td><pre><a name="line72">72</a>   def self.generate_orgs</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line73">73</a>     User.transaction do</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line74">74</a>       (1..10).each do</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line75">75</a>         org = User.new</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line76">76</a>         org.name = &quot;机构试用帐号&quot;</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line77">77</a>         org.username = rendom_str(6)</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line78">78</a>         pass = rendom_str(6)</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line79">79</a>         org.password = pass</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line80">80</a>         org.password_confirmation = pass</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line81">81</a>         org.pass = pass</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line82">82</a>         org.user_type = 'org'</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line83">83</a>         org.account_num = 100</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line84">84</a>         org.save</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line85">85</a> </pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line86">86</a>         ur_update(org.id, 3)</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line87">87</a>         add_surveys_for_org(org)</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line88">88</a>       end</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line89">89</a>     end</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line90">90</a>   end</pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line91">91</a> </pre></td>
          </tr>
        
          
          
          <tr class="marked">
            <td><pre><a name="line92">92</a>   def self.rendom_str(num)</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line93">93</a>      @str=&quot;&quot;</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line94">94</a>      for i in 1..num</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line95">95</a>       if i%2==0</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line96">96</a>          @str += (97+rand(26)).chr.to_s</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line97">97</a>       else</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line98">98</a>         @str +=rand(10).to_s</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line99">99</a>       end</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line100">100</a>      end</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line101">101</a>      @str</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line102">102</a>   end</pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line103">103</a>   </pre></td>
          </tr>
        
          
          
          <tr class="marked">
            <td><pre><a name="line104">104</a>   protected</pre></td>
          </tr>
        
          
          
          <tr class="marked">
            <td><pre><a name="line105">105</a>   def self.encrypted_passwed(password, salt)</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line106">106</a>     string_to_hash = &quot;#{password}xinjiayuan#{salt}&quot;</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line107">107</a>     Digest::SHA1.hexdigest(string_to_hash)</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line108">108</a>   end</pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line109">109</a>   </pre></td>
          </tr>
        
          
          
          <tr class="marked">
            <td><pre><a name="line110">110</a>   def validate_on_create</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line111">111</a>     if self.password != self.password_confirmation</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line112">112</a>       errors.add(:password_confirmation, &quot;两次输入的密码不一致&quot;)</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line113">113</a>     end</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line114">114</a>   end</pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line115">115</a> </pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line116">116</a>   #赋予机构用户的角色</pre></td>
          </tr>
        
          
          
          <tr class="marked">
            <td><pre><a name="line117">117</a>   def self.ur_update(u_id, r_id)</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line118">118</a> </pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line119">119</a>     temp_ur = UserRole.find_by_sql(&quot;select id from user_roles where user_id= #{u_id} and  role_id = #{r_id}&quot;)</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line120">120</a>     if temp_ur.length == 0</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line121">121</a>       UserRole.add(u_id.to_s, r_id.to_s)</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line122">122</a>     else</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line123">123</a>       UserRole.del(u_id.to_s, r_id.to_s)</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line124">124</a>     end</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line125">125</a>   end</pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line126">126</a> </pre></td>
          </tr>
        
          
          
          <tr class="inferred">
            <td><pre><a name="line127">127</a>   #给机构试用帐号给量表</pre></td>
          </tr>
        
          
          
          <tr class="marked">
            <td><pre><a name="line128">128</a>   def self.add_surveys_for_org(org)</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line129">129</a> </pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line130">130</a>     params = Hash.new</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line131">131</a>     params[:org] = Hash.new</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line132">132</a>     params[:org][:test_ids] = [37, 41, 54, 84, 94, 99, 100]</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line133">133</a> </pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line134">134</a>     org.update_attributes(params[:org])</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line135">135</a>   end</pre></td>
          </tr>
        
          
          
          <tr class="uncovered">
            <td><pre><a name="line136">136</a> end</pre></td>
          </tr>
        
      </tbody>
    </table>

    <p>Generated on Wed Mar 17 14:12:44 +0800 2010 with <a href="http://github.com/relevance/rcov">rcov 0.9.8</a></p>

  </body>
</html>
